import React from "react";
import { BigNumber, ethers } from 'ethers';
import { useCallback, useMemo } from 'react';
import { useHasPendingApproval, useTransactionAdder } from '../state/transactions/hooks';
import useAllowance from './useAllowance';
import ERC20 from '../basis-cash/ERC20';
import useBasisCash from "./useBasisCash";

const APPROVE_AMOUNT = ethers.constants.MaxUint256;
const APPROVE_BASE_AMOUNT = BigNumber.from('1000000000000000000000000');

export enum ApprovalState {
  UNKNOWN,
  NOT_APPROVED,
  PENDING,
  APPROVED,
}

// returns a variable indicating the state of the approval and a function which approves if necessary or early returns
function useApprove721(erc721: string, spender: string,fishNumber:number): [ApprovalState, () => Promise<void>] {
  const basisCash = useBasisCash();
  const [approveStatus,setApproveState] = React.useState(ApprovalState.NOT_APPROVED);
  const contract = basisCash.contracts.FishCard;
  React.useEffect(()=>{
    contract.getApproved(fishNumber)
        .then((res:string)=>{
          console.log(res,"-----")
          if(res===spender){
            setApproveState(ApprovalState.APPROVED);
          }
        })
  },[basisCash])
  const approve = ()=>{
    return contract.approve(spender,fishNumber);
  }
  return [approveStatus,approve];
}

export default useApprove721;
